import { Module } from "vuex";
import { Session } from "@/utils/storage";
import { I_UserInfos, UserInfosState, RootStateTypes } from '@/store/interface/index';

const userInfosModule:Module<UserInfosState, RootStateTypes> = {
    namespaced: true,
    state: {
        userInfos: {
            userName: 'test',
            photo: 'https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=1813762643,1914315241&fm=26&gp=0.jpg'
        }
    },
    mutations: {
        getUserInfos(state, data: I_UserInfos){
            state.userInfos = data
        }
    },
    actions: {
       async setUserInfos({commit}, data: I_UserInfos) {
           if(data) {
               commit('getUserInfos', data)
           } else {
               const getUserInfos = Session.get('userInfo')
               if(getUserInfos) {
                   commit('getUserInfos', getUserInfos)
               }
           }
       }
    }
}
export default userInfosModule